from rest_framework.throttling import SimpleRateThrottle


class SMSThrottle(SimpleRateThrottle):
    scope = 'sms'

    def get_cache_key(self, request, view):
        """
        返回的字段就是用于频率限制的字段
        """
        telephone = request.query_params.get('telephone')
        # 'throttle_%(scope)s_%(ident)s'

        return self.cache_format % {"scope": self.scope, "ident": telephone}
